<template>
  <div class="bgWhite">
    <h2 class="title2 bold">资质申报人员</h2>
    <Table
        :columns="config.columns"
        :row-key="(record,index) => index"
        :data-source="config.list"
        :pagination="config.page"
        :loading="config.loading"
        @change="(pagination)=> changeHandler(pagination, config)"
        bordered
    >
      <template #indexSlot="{ index }">{{(config.page.current-1)*10+index+1}}</template>
      <template #name="{ text, record }">
        <router-link target="_blank" :to="{ path: `/staff/${record.staffId}` }" class="blue" >
          {{ text }}
        </router-link>
      </template>
    </Table>
  </div>
</template>

<script lang="ts">
import {defineComponent, inject, onMounted, reactive, toRefs} from 'vue';
import { Table } from 'ant-design-vue';
import { getApplyPersonApi  } from '/@/api/foreign';


const columns = [
  { title: '序号', dataIndex: 'index', width: 70, align: 'center', slots: ({ customRender: 'indexSlot' }) },
  { title: '姓名', dataIndex: 'staffName', slots: ({ customRender: 'name' }) },
  { title: '证书类型', dataIndex: 'objQualName'},
  { title: '证书类别', dataIndex: 'certTypeName'},
  { title: '证书专业', dataIndex: 'certProfName' },
  { title: '证书编号', dataIndex: 'certNo' }
]

export default defineComponent({
  components: {
    Table
  },
  setup() {
    const applyId = inject('applyId') as string;
    const config = reactive({
      columns,
      list: [],
      loading: false,
      page: {
        total: 0,
        current: 1
      }
    })

    const changeHandler = (pagination, config) => {
      const { current } = pagination;
      let { loading, list, page } = toRefs(config);
      loading.value = true;
      getApplyPersonApi( { applyId, current }).then( ({ data,success } ) => {
        if(success){
          let { records, current, total } = data;
          list.value = records;
          loading.value = false;
          page.value = {current, total};
        }
      })
    }

    const init = () => {
      changeHandler({current: 1}, config);
    }

    onMounted(init)

    return {
      config, changeHandler
    }
  }
})
</script>

<style lang="less" scoped>

.bgWhite{
  padding: 15px 30px 30px;
}

.ant-col{
  padding-top: 16px;
  margin-bottom: 8px;
}

.ant-select ,.ant-btn{
  width: 100%;
}

.ant-col.text-right{
  padding-right: 0 !important;
}

</style>
